package main

import (
	"fmt"
	"reflect"
	"strings"
)

type order struct {
	ordId      int
	customerId int
}

type employee struct {
	name    string
	id      int
	address string
	salary  int
	country string
}

func main() {
	o := order{
		ordId:      456,
		customerId: 56,
	}
	e := employee{
		name:    "Naveen",
		id:      565,
		address: "Coimbatore",
		salary:  90000,
		country: "India",
	}
	i := 90
	Run(o, e, i)

}

func Run(item ...interface{}) {
	for _, v := range item {
		ItemInterface(v)
	}
}

func ItemInterface(item interface{}) {
	strBuf := strings.Builder{}
	itemValueOf := reflect.ValueOf(item)

	if itemValueOf.Kind() != reflect.Struct {
		fmt.Println("unsupported type")
		return
	}
	strBuf.Write([]byte(fmt.Sprintf("insert into %v values (", itemValueOf.Type().Name())))

	for i := 0; i < itemValueOf.NumField(); i++ {

		switch itemValueOf.Field(i).Type().Kind() {
		case reflect.String:
			strBuf.Write([]byte("\""))
			strBuf.Write([]byte(itemValueOf.Field(i).String()))
			strBuf.Write([]byte("\""))
		case reflect.Int:
			strBuf.Write([]byte(fmt.Sprintf("%d", itemValueOf.Field(i).Int())))
		default:

		}
		if i < itemValueOf.NumField()-1 {
			strBuf.Write([]byte(","))
		}

	}
	strBuf.Write([]byte(")"))
	fmt.Println(strBuf.String())
}
